<template>
  <div class="app-container">
    <el-dialog :title="pageTitle" :visible.sync="dialogFormVisible" :before-close="beforeClose" width="30%">
      <el-input v-model="data" :placeholder="placeHolder" />
			<el-input v-if="type=='jf'||type=='gold'||type=='jgz'" v-model="mark" placeholder="请输入变动原因" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="canel">取 消</el-button>
        <el-button v-if="type=='jf'||type=='gold'||type=='jgz'" type="danger" @click="sure('reduce')">减 少</el-button>
        <el-button v-if="type=='jf'||type=='gold'||type=='jgz'" type="success" @click="sure('add')">增 加</el-button>
        <el-button v-if="type=='phone'||type=='true_name'" type="primary" @click="sure('set')">保 存</el-button>
        <el-button v-if="type=='team_id'" type="primary" @click="sure('upgrade')">升级</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { Message } from 'element-ui'
import { handle } from '@/api/member'
export default {
  name: 'MemberHandle',
  data() {
    return {
      data: '',
      dialogFormVisible: false,
      pageTitle: '',
      placeHolder: '',
      id: '',
      type: '',
      awardName: '',
			mark: '',
    }
  },

  methods: {
    beforeClose() {
      this.canel()
    },
    canel() {
      this.dialogFormVisible = false
    },

    init() {
      switch (this.type) {
        case 'gold':
          this.pageTitle = '余额变动'
          this.placeHolder = '请输入变动余额（单位元）'
          break
        case 'jf':
          this.pageTitle = '积分变动'
          this.placeHolder = '请输入变动积分'
          break
        case 'jgz':
          this.pageTitle = this.awardName+'变动'
          this.placeHolder = '请输入变动'+this.awardName+'（单位元）'
          break
        case 'true_name':
          this.pageTitle = '修改姓名'
          this.placeHolder = '请输入姓名'
          break
        case 'phone':
          this.pageTitle = '修改手机'
          this.placeHolder = '请输入手机号'
          break
        case 'team_id':
          this.pageTitle = '升级报单中心'
          this.placeHolder = '请输入后台账号密码'
          break
      }
    },

    handle(id, type, awardName) {
      this.dialogFormVisible = true
      this.type = type
      this.id = id
      this.data = ''
      this.awardName = awardName
      this.init()
    },

    sure(handleType) {
      handle({ id: this.id, type: this.type, data: this.data, mark:this.mark, handleType }).then(res => {
        Message.success('操作成功')
        this.$emit('afterSave')
        this.canel()
      })
    }
  }
}
</script>
